package com.spic.business.safetyactivity.controller;

import com.spic.business.safetyactivity.domain.SafetyActivity;
import com.spic.business.safetyactivity.service.ISafetyActivityService;
import com.spic.common.core.utils.poi.ExcelUtil;
import com.spic.common.core.web.controller.BaseController;
import com.spic.common.core.web.domain.AjaxResult;
import com.spic.common.core.web.page.TableDataInfo;
import com.spic.common.log.annotation.Log;
import com.spic.common.log.enums.BusinessType;
import com.spic.common.security.annotation.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * 安全活动记录Controller
 * 
 * @author spic
 * @date 2022-06-14
 */
@RestController
@RequestMapping("/activity")
public class SafetyActivityController extends BaseController
{
    @Autowired
    private ISafetyActivityService safetyActivityService;

    /**
     * 查询安全活动记录列表
     */
    @GetMapping("/list")
    public TableDataInfo list(SafetyActivity safetyActivity)
    {
        startPage();
        List<SafetyActivity> list = safetyActivityService.selectSafetyActivityList(safetyActivity);
        return getDataTable(list);
    }

    /**
     * 导出安全活动记录列表
     */
    @PreAuthorize(hasPermi = "business:safetyActivity:export")
    @Log(title = "安全活动记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SafetyActivity safetyActivity) throws IOException {
        List<SafetyActivity> list = safetyActivityService.selectSafetyActivityList(safetyActivity);
        ExcelUtil<SafetyActivity> util = new ExcelUtil<SafetyActivity>(SafetyActivity.class);
        util.exportExcel(response, list, "安全活动记录数据");
    }

    /**
     * 获取安全活动记录详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(safetyActivityService.selectSafetyActivityById(id));
    }

    /**
     * 新增安全活动记录
     */
    @Log(title = "安全活动记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@Validated @RequestBody SafetyActivity safetyActivity)
    {
        return toAjax(safetyActivityService.insertSafetyActivity(safetyActivity));
    }

    /**
     * 修改安全活动记录
     */
    @PreAuthorize(hasPermi = "business:safetyActivity:edit")
    @Log(title = "安全活动记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SafetyActivity safetyActivity)
    {
        return toAjax(safetyActivityService.updateSafetyActivity(safetyActivity));
    }


    @PreAuthorize(hasPermi = "business:safetyActivity:instruct")
    @Log(title = "安全活动记录", businessType = BusinessType.UPDATE)
    @PutMapping("/instruct")
    public AjaxResult instruct(@RequestBody SafetyActivity safetyActivity)
    {
        return toAjax(safetyActivityService.updateSafetyActivity(safetyActivity));
    }

    /**
     * 删除安全活动记录
     */
    @Log(title = "安全活动记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(safetyActivityService.deleteSafetyActivityByIds(ids));
    }
}
